package org.txazo.music.web.action.json;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.txazo.music.service.UserService;
import org.txazo.music.util.map.RegisterCache;
import org.txazo.music.web.action.base.JsonBaseAction;

/**
 * UserJsonAction
 * 
 * @author Tu XiaoZhou
 * @since 2013-04-12
 * 
 */
@Controller
@Scope("session")
public class UserJsonAction extends JsonBaseAction {

	private static final long serialVersionUID = 1L;

	/** 邮箱帐号 */
	private String account;

	/** 邮箱帐号是否已经存在的标识 */
	private int flag;

	@Autowired
	private UserService userService;

	@Action(value = "emailAccountExists", results = { @Result(name = SUCCESS, type = "json") })
	public String isAccountExists() {
		if (userService.isAccountExist(account)
				|| RegisterCache.exists(account)) {
			flag = 1;
		} else {
			flag = 0;
		}

		return SUCCESS;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

}
